package bb.lanxing.lib.devices.ble.ble.characteristic.radar;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleCharacteristic;
import bb.lanxing.lib.devices.ble.ble.base.BaseBleService;
import bb.lanxing.lib.kt.ByteArrayExtKt;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import kotlin.Metadata;
import kotlin.collections.ArraysKt;
import kotlin.internal.ProgressionUtilKt;
import kotlin.jvm.internal.Intrinsics;
import kotlin.ranges.IntRange;

public final class RadarMeasurementCharacteristics extends BaseBleCharacteristic {
    public RadarMeasurementCharacteristics(BaseBleService bleService) {
        super(bleService);
        Intrinsics.checkNotNullParameter(bleService, "bleService");
    }

    @Override
    public UUID targetUUID() {
        UUID fromString = UUID.fromString("6A4E3203-667B-11E3-949A-0800200C9A66");
        Intrinsics.checkNotNullExpressionValue(fromString, "fromString(BLEAttributes…_LIGHT_RADAR_MEASUREMENT)");
        return fromString;
    }

    @Override
    public void onValueUpdate(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        Intrinsics.checkNotNullParameter(gatt, "gatt");
        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        byte[] value = characteristic.getValue();
        Intrinsics.checkNotNullExpressionValue(value, "characteristic.value");
        generateThreatData(value);
    }

    public List<ThreatData> generateThreatData(byte[] raw) {
        Intrinsics.checkNotNullParameter(raw, "raw");
        ArrayList arrayList = new ArrayList();
        IntRange intRange = new IntRange(1, ArraysKt.getLastIndex(raw));
        int first = intRange.getFirst();
        int progressionLastElement = ProgressionUtilKt.getProgressionLastElement(first, intRange.getLast(), 3);
        if (first <= progressionLastElement) {
            while (true) {
                int readUInt8 = ByteArrayExtKt.readUInt8(raw, first);
                int readUInt82 = ByteArrayExtKt.readUInt8(raw, first + 1);
                ThreatLevel from = ThreatLevel.Companion.from(ByteArrayExtKt.readUInt8(raw, first + 2));
                Intrinsics.checkNotNull(from);
                arrayList.add(new ThreatData(readUInt8, readUInt82, from));
                if (first == progressionLastElement) {
                    break;
                }
                first += 3;
            }
        }
        return arrayList;
    }
}
